<?php 


function export_csv($arr,$filename,$i=0) {
	if($i==0){
 		header("Content-type:text/csv");
		header("Content-Disposition:attachment;filename=".$filename);
		header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
		header('Expires:0');
		header('Pragma:public'); 
		
	/* 	header( "Cache-Control: public" );
		header( "Pragma: public" );
		header("Content-type:application/vnd.ms-excel");
		header("Content-Disposition:attachment;filename=$fileName");
		header('Content-Type:APPLICATION/OCTET-STREAM'); */
		ob_start();
		ob_end_clean();
		echo pack('H*','EFBBBF');
	}
	echo ($arr);
}




function array_to_program_string($result,$radioid,$i=0) {
	if(empty($result)) {
		#return i("没有符合您要求的数据！^_^");
		return '';
	}
	if($i ==0){
		$data = 'radioid,title,broadcaster,broadcasttime,playurl'."\n"; //栏目名称
	}
	$size_result = sizeof($result);
	for($i = 0 ; $i < $size_result ; $i++) {
		$yize_result = sizeof($result[$i]['programs']);
		for($y = 0;$y < $yize_result;$y++){
		$data .= i($radioid.','.$result[$i]['programs'][$y]['title'].','.$result[$i]['programs'][$y]['broadcaster'].','.$result[$i]['programs'][$y]['broadcasttime'].','.$result[$i]['programs'][$y]['playurl'])."\n";
		}
	}
	return $data;
}

function array_to_radio_string($result) {
	if(empty($result)) {
		#return i("没有符合您要求的数据！^_^");
		return '';
	}
	$data = 'radioid,name,type,frequency,region,description'."\n"; //栏目名称
	$size_result = sizeof($result);
		for($y = 0;$y < $size_result;$y++){
			if(isset($result[$y]['channelid'])){
				
		$data .= i($result[$y]['channelid'].','.$result[$y]['name'].','.$result[$y]['type'].','.$result[$y]['frequency'].','.$result[$y]['region'].','.str_replace(array("\r","\n"), '', $result[$y]['description']))."\n";
			}
		}
	
	return $data;
}

function i($strInput) {
	return iconv('utf-8','GBK//IGNORE',$strInput);//页面编码为utf-8时使用，否则导出的中文为乱码
}